@{
    ViewData["Title"] = "智能车间生产管控大屏";
    Layout = null; // 使用无布局的全屏模式
}

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"]</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #0a1a2e 0%, #16213e 50%, #0f3460 100%);
            color: #ffffff;
            overflow-x: hidden;
        }

        .dashboard-container {
            width: 100%;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 头部样式 */
        .header {
            background: rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
            padding: 15px 0;
            text-align: center;
            border-bottom: 2px solid rgba(0, 255, 255, 0.3);
            position: relative;
        }

        .header-title {
            font-size: 2.2rem;
            font-weight: bold;
            color: #00ffff;
            text-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
            margin: 0;
            animation: pulse 2s infinite;
        }

        .header-time {
            position: absolute;
            top: 15px;
            right: 30px;
            font-size: 1.1rem;
            color: #00ffff;
            font-weight: 600;
            text-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
            z-index: 1001;
        }

        /* 脉冲动画 */
        @@keyframes pulse {
            0% {
                transform: scale(1);
                opacity: 1;
            }

            50% {
                transform: scale(1.05);
                opacity: 0.8;
            }

            100% {
                transform: scale(1);
                opacity: 1;
            }
        }

        /* 主内容区域 - 改为4x3网格布局 */
        .main-content {
            flex: 1;
            padding: 15px;
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            grid-template-rows: repeat(3, 1fr);
            gap: 15px;
            height: calc(100vh - 90px);
        }

        /* 卡片基础样式 */
        .card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(0, 255, 255, 0.2);
            border-radius: 12px;
            padding: 15px;
            transition: all 0.3s ease;
            overflow: hidden;
        }

        .card:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0, 255, 255, 0.2);
            border-color: rgba(0, 255, 255, 0.5);
        }

        .card-title {
            font-size: 1.1rem;
            color: #00ffff;
            margin-bottom: 12px;
            text-align: center;
            border-bottom: 1px solid rgba(0, 255, 255, 0.3);
            padding-bottom: 8px;
            font-weight: 600;
        }

        /* 实时数据汇总 - 左上角大卡片 */
        .realtime-summary {
            grid-column: 1 / 3;
            grid-row: 1;
        }

        .summary-metrics {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
            margin-top: 10px;
        }

        .metric-card {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            padding: 12px;
            text-align: center;
            border-left: 3px solid;
        }

        .metric-card.equipment {
            border-left-color: #4CAF50;
        }

        .metric-card.quality {
            border-left-color: #2196F3;
        }

        .metric-card.efficiency {
            border-left-color: #FF9800;
        }

        .metric-card.output {
            border-left-color: #9C27B0;
        }

        .metric-card.personnel {
            border-left-color: #00BCD4;
        }

        .metric-card.defect {
            border-left-color: #F44336;
        }

        .metric-value {
            font-size: 1.3rem;
            font-weight: bold;
            color: #00ffff;
            margin: 8px 0;
        }

        .metric-label {
            font-size: 0.8rem;
            color: #a0c4ff;
        }

        /* 生产统计汇总 */
        .production-summary {
            grid-column: 3;
            grid-row: 1;
        }

        .summary-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px;
            margin: 5px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid #4CAF50;
        }

        .summary-label {
            color: #a0c4ff;
            font-size: 0.9rem;
        }

        .summary-value {
            color: #00ffff;
            font-weight: bold;
            font-size: 1rem;
        }

        /* 员工绩效Top5 */
        .employee-performance {
            grid-column: 4;
            grid-row: 1;
        }

        .performance-list {
            max-height: 200px;
            overflow-y: auto;
        }

        .performance-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px;
            margin: 3px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid #FF9800;
            font-size: 0.85rem;
        }

        .performance-item .rank {
            font-weight: bold;
            color: #ffd700;
            width: 15px;
        }

        .performance-item .name {
            flex: 1;
            margin: 0 5px;
            color: #ffffff;
        }

        .performance-item .score {
            color: #FF9800;
            font-weight: bold;
        }

        /* 产量统计表格 */
        .production-statistics-card {
            grid-column: 1 / 3;
            grid-row: 2;
        }

        .production-statistics-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            font-size: 0.9rem;
        }

        .production-statistics-table th,
        .production-statistics-table td {
            padding: 8px;
            text-align: center;
            border-bottom: 1px solid rgba(0, 255, 255, 0.2);
        }

        .production-statistics-table th {
            background: rgba(0, 255, 255, 0.1);
            color: #00ffff;
            font-weight: bold;
        }

        .production-statistics-table td {
            color: #ffffff;
        }

        .production-statistics-table tr:hover {
            background: rgba(0, 255, 255, 0.1);
        }

        /* 工序统计 */
        .process-stats {
            grid-column: 3;
            grid-row: 2;
        }

        .process-tabs {
            display: flex;
            margin-bottom: 10px;
        }

        .process-tab {
            flex: 1;
            padding: 5px;
            background: rgba(255, 255, 255, 0.1);
            border: none;
            color: #a0c4ff;
            cursor: pointer;
            font-size: 0.8rem;
            border-radius: 4px;
            margin: 0 2px;
        }

        .process-tab.active {
            background: rgba(0, 255, 255, 0.2);
            color: #00ffff;
        }

        .process-content {
            max-height: 180px;
            overflow-y: auto;
        }

        .process-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px;
            margin: 3px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid #2196F3;
            font-size: 0.85rem;
        }

        .process-item .name {
            flex: 1;
            color: #ffffff;
        }

        .process-item .value {
            color: #2196F3;
            font-weight: bold;
        }

        /* 销售订单统计 */
        .sales-summary {
            grid-column: 4;
            grid-row: 2;
        }

        /* 不良品分布Top5 */
        .defective-distribution-card {
            grid-column: 1;
            grid-row: 3;
        }

        .defective-top5-list {
            max-height: 180px;
            overflow-y: auto;
        }

        .defective-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px;
            margin: 3px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid #ff6b6b;
            font-size: 0.85rem;
        }

        .defective-item .rank {
            font-weight: bold;
            color: #ffd700;
            width: 15px;
        }

        .defective-item .name {
            flex: 1;
            margin-left: 8px;
            color: #ffffff;
        }

        .defective-item .count {
            color: #ff6b6b;
            font-weight: bold;
        }

        .defective-item .percentage {
            color: #00ffff;
            font-size: 0.8rem;
        }

        /* 工单效率Top5 */
        .workorder-efficiency-card {
            grid-column: 2;
            grid-row: 3;
        }

        .workorder-efficiency-list {
            max-height: 180px;
            overflow-y: auto;
        }

        .efficiency-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px;
            margin: 3px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid #4CAF50;
            font-size: 0.8rem;
        }

        .efficiency-item .rank {
            font-weight: bold;
            color: #ffd700;
            width: 15px;
        }

        .efficiency-item .workorder {
            color: #00ffff;
            width: 50px;
        }

        .efficiency-item .product {
            flex: 1;
            margin: 0 5px;
            color: #ffffff;
        }

        .efficiency-item .efficiency {
            color: #4CAF50;
            font-weight: bold;
        }

        /* 生产趋势图表 */
        .trend-chart-card {
            grid-column: 3 / 5;
            grid-row: 3;
        }

        .trend-chart-container {
            height: 180px;
            position: relative;
        }

        /* 控制按钮 */
        .fullscreen-btn,
        .back-btn {
            position: fixed;
            top: 15px;
            background: rgba(0, 255, 255, 0.2);
            border: 1px solid rgba(0, 255, 255, 0.5);
            color: #00ffff;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            z-index: 1000;
            text-decoration: none;
            font-size: 0.9rem;
        }

        .fullscreen-btn {
            left: 20px;
        }

        .back-btn {
            left: 120px;
            background: rgba(255, 255, 255, 0.2);
            border-color: rgba(255, 255, 255, 0.5);
            color: #ffffff;
        }

        .fullscreen-btn:hover,
        .back-btn:hover {
            background: rgba(0, 255, 255, 0.3);
            transform: scale(1.05);
        }

        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            color: #ffffff;
        }

        /* 自定义滚动条 */
        .defective-top5-list::-webkit-scrollbar,
        .workorder-efficiency-list::-webkit-scrollbar,
        .performance-list::-webkit-scrollbar,
        .process-content::-webkit-scrollbar {
            width: 4px;
        }

        .defective-top5-list::-webkit-scrollbar-track,
        .workorder-efficiency-list::-webkit-scrollbar-track,
        .performance-list::-webkit-scrollbar-track,
        .process-content::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 2px;
        }

        .defective-top5-list::-webkit-scrollbar-thumb,
        .workorder-efficiency-list::-webkit-scrollbar-thumb,
        .performance-list::-webkit-scrollbar-thumb,
        .process-content::-webkit-scrollbar-thumb {
            background: rgba(0, 255, 255, 0.5);
            border-radius: 2px;
        }

        /* 响应式设计 */
        @@media (max-width: 1400px) {
            .main-content {
                grid-template-columns: repeat(3, 1fr);
                grid-template-rows: repeat(4, 1fr);
            }

            .realtime-summary {
                grid-column: 1 / 3;
                grid-row: 1;
            }

            .production-statistics-card {
                grid-column: 1 / 4;
                grid-row: 2;
            }

            .trend-chart-card {
                grid-column: 1 / 4;
                grid-row: 4;
            }
        }

        @@media (max-width: 768px) {
            .header-title {
                font-size: 1.6rem;
            }

            .main-content {
                padding: 10px;
                grid-template-columns: 1fr;
                grid-template-rows: repeat(8, auto);
            }

            .realtime-summary,
            .production-statistics-card,
            .trend-chart-card {
                grid-column: 1;
            }
        }
    </style>
</head>

<body>
    <div class="dashboard-container">
        <!-- 头部标题区域 -->
        <header class="header">
            <h1 class="header-title">🏭 智能车间生产管控大屏</h1>
            <div class="header-time" id="currentTime"></div>
        </header>

        <button class="fullscreen-btn" id="fullscreenBtn">
            <i class="fas fa-expand"></i> 全屏
        </button>

        <a href="@Url.Action("Index", "Kanban")" class="back-btn" id="backBtn">
            <i class="fas fa-arrow-left"></i> 返回
        </a>

        <!-- 主内容区域 -->
        <main class="main-content">
            <!-- 实时数据汇总 -->
            <div class="card realtime-summary">
                <h3 class="card-title">实时数据汇总</h3>
                <div class="summary-metrics">
                    <div class="metric-card equipment">
                        <div class="metric-value" id="equipmentUtilization">95%</div>
                        <div class="metric-label">设备利用率</div>
                    </div>
                    <div class="metric-card quality">
                        <div class="metric-value" id="qualityRate">96%</div>
                        <div class="metric-label">良品率</div>
                    </div>
                    <div class="metric-card efficiency">
                        <div class="metric-value" id="efficiency">92%</div>
                        <div class="metric-label">工作效率</div>
                    </div>
                    <div class="metric-card output">
                        <div class="metric-value" id="dailyOutput">1200</div>
                        <div class="metric-label">日产量</div>
                    </div>
                    <div class="metric-card personnel">
                        <div class="metric-value" id="onlinePersonnel">25</div>
                        <div class="metric-label">在线人数</div>
                    </div>
                    <div class="metric-card defect">
                        <div class="metric-value defect-rate-value">0.0%</div>
                        <div class="metric-label">不良率</div>
                    </div>
                </div>
            </div>

            <!-- 生产统计汇总 -->
            <div class="card production-summary">
                <h3 class="card-title">生产统计汇总</h3>
                <div class="summary-item">
                    <span class="summary-label">总良品数</span>
                    <span class="summary-value" id="totalGoodQuantity">0</span>
                </div>
                <div class="summary-item">
                    <span class="summary-label">总不良品数</span>
                    <span class="summary-value" id="totalBadQuantity">0</span>
                </div>
                <div class="summary-item">
                    <span class="summary-label">良品率</span>
                    <span class="summary-value" id="goodRate">0%</span>
                </div>
                <div class="summary-item">
                    <span class="summary-label">总工单数</span>
                    <span class="summary-value" id="totalWorkOrders">0</span>
                </div>
            </div>

            <!-- 员工绩效Top5 -->
            <div class="card employee-performance">
                <h3 class="card-title">员工绩效Top5</h3>
                <div class="performance-list">
                    <!-- 动态生成员工绩效排名 -->
                </div>
            </div>

            <!-- 产量统计表格 -->
            <div class="card production-statistics-card">
                <h3 class="card-title">产量统计明细</h3>
                <table class="production-statistics-table">
                    <thead>
                        <tr>
                            <th>日期</th>
                            <th>产品名称</th>
                            <th>计划数量</th>
                            <th>良品数量</th>
                            <th>不良品数</th>
                            <th>完成率</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- 动态生成表格内容 -->
                    </tbody>
                </table>
            </div>

            <!-- 工序统计 -->
            <div class="card process-stats">
                <h3 class="card-title">工序统计Top5</h3>
                <div class="process-tabs">
                    <button class="process-tab active" data-tab="plan">计划数</button>
                    <button class="process-tab" data-tab="report">报工数</button>
                </div>
                <div class="process-content" id="processContent">
                    <!-- 动态生成工序统计 -->
                </div>
            </div>

            <!-- 销售订单统计 -->
            <div class="card sales-summary">
                <h3 class="card-title">销售订单统计</h3>
                <div class="summary-item">
                    <span class="summary-label">总订单数</span>
                    <span class="summary-value" id="totalOrders">0</span>
                </div>
                <div class="summary-item">
                    <span class="summary-label">总产品数</span>
                    <span class="summary-value" id="totalProducts">0</span>
                </div>
                <div class="summary-item">
                    <span class="summary-label">订单完成率</span>
                    <span class="summary-value" id="orderCompletionRate">0%</span>
                </div>
            </div>

            <!-- 不良品分布Top5 -->
            <div class="card defective-distribution-card">
                <h3 class="card-title">不良品分布Top5</h3>
                <div class="defective-top5-list">
                    <!-- 动态生成不良品排名 -->
                </div>
            </div>

            <!-- 工单执行效率Top5 -->
            <div class="card workorder-efficiency-card">
                <h3 class="card-title">工单效率Top5</h3>
                <div class="workorder-efficiency-list">
                    <!-- 动态生成工单效率排名 -->
                </div>
            </div>

            <!-- 生产趋势图表 -->
            <div class="card trend-chart-card">
                <h3 class="card-title">生产趋势</h3>
                <div class="trend-chart-container">
                    <canvas id="trendChart"></canvas>
                </div>
            </div>
        </main>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/dashboard.js"></script>
    <script>
        // 将API URL传递给JavaScript
        window.readApiUrl = '@ViewBag.ReadApiUrl';
    </script>
</body>

</html>